package com.gray.wow.common;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateUtil {
	public static final String PATTERN_DAY = "yyyy-MM-dd";
	public static final String PATTERN_SECOND = "yyyy-MM-dd HH:mm:ss";

	// 按照指定格式如yyyy-MM-dd获取当前时间
	public static String getDateStr(String pattern, Date date) {
		if (date == null) {
			return null;
		}
		SimpleDateFormat sf = new SimpleDateFormat(pattern);

		return sf.format(date);
	}

	public static String getDateStr(String pattern, String date) throws ParseException {
		if (date == null) {
			return null;
		}
		SimpleDateFormat sf = new SimpleDateFormat(pattern);
		
		return sf.format(sf.parse(date));
	}
}
